package com.biz.primus.base.support.rest.vo;

import com.biz.primus.base.exception.BizException;
import com.biz.primus.base.exception.ExceptionType;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 *
 *
 * @author yanweijin
 * @date 2017/11/29
 */
@Getter
@NoArgsConstructor
public class JsonResult {

	private int code = 0;

	private String msg = "success";

	private long ts = System.currentTimeMillis();

	private Object data;

	/**
	 * 失败的调用,返回异常码和消息
	 * @param code
	 * @param msg
	 */
	public JsonResult(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	/**
	 * 成功的调用,返回数据
	 * @param data
	 */
	public JsonResult(Object data) {
		this.data = data;
	}

	public JsonResult(ExceptionType exceptionType){
		this(exceptionType.getCode(),exceptionType.getDescription());
	}

	public JsonResult(BizException bizException){
		this(bizException.getCode(),bizException.getDescription());
	}


}
